<template>
  <div class="update-userinfo">
      <div class="container">
          <el-form ref="userinfoForm" :model="userinfoForm" label-width="100px">
            <el-form-item label="用户编号">
                <el-input disabled v-model="userinfoForm.userid"></el-input>
            </el-form-item>
            <el-form-item label="用户姓名">
                <el-input disabled v-model="userinfoForm.realname"></el-input>
            </el-form-item>
            <el-form-item label="用户手机">
                <el-input disabled v-model="userinfoForm.phone"></el-input>
            </el-form-item>
            <el-form-item label="用户等级">
                <el-select v-model="userinfoForm.grade" placeholder="请选择用户等级">
                    <el-option
                        v-for="item in grade_list"
                        :key="item.grade"
                        :label="item.name"
                        :value="item.grade">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="更改">
                <el-button @click="updataUserinfo" type="danger">提交更改</el-button>
            </el-form-item>
          </el-form>
      </div>     
  </div>
</template>

<script>
export default {
  name:'update-userinfo',
  props:{
      cell:{
          type:Object,
          default:function(){
              return {}
          }
      }
  },
  data () {
    return {
        userinfoForm:{
            userid:null,
            realname:null,
            phone:null,
            grade:null
        },
        grade_list:[]
    };
  },
  components: {},
  created() {
      this.init();
      this.getGredeList();
  },
  mounted() {},
  methods: {
      init(){
          this.userinfoForm.userid = this.cell.userid;
          this.userinfoForm.realname = this.cell.realname;
          this.userinfoForm.phone = this.cell.phone;
          this.userinfoForm.grade = this.cell.grade;
      },
      getGredeList(){
          let brandId = sessionStorage.getItem(3) || 407;
          let token = sessionStorage.getItem(1);
          let url = `user/thirdlevel/prod/brand/${brandId}/${token}`;
          this.$Http.get(url).then(res=>{
              if(res.data.resp_code === "000000"){
                  this.grade_list = res.data.result.tld;
              }else{
                  this.$message(res.data.resp_message);
              }
          }).catch(err=>{

          })
      },
      updataUserinfo(){
          let url = `user/grade/update`,
              params = `id=${this.userinfoForm.userid}&grade=${this.userinfoForm.grade}`;
          this.$Http.post(url,params).then(res=>{
              if(res.data.resp_code === "000000"){
                  this.$message({
                      type:"success",
                      message:"修改级别成功！"
                  })
              }else{
                  this.$notify.info({
                        title: '提示',
                        message: res.data.resp_message
                    }); 
              }
          }).catch(err=>{
               this.$notify.error({
                        title: '提示',
                        message: "修改失败！"
                }); 
          })
      }
  }
}

</script>
<style scoped>
.container{
    min-width: 300px;
    min-height: 300px;
    padding: 20px 40px;
}
</style>